package com.example.kotlinlearn.kotlinLearn

import kotlin.random.Random

//单例类，只允许被创建一次
object SingeLeton {

    private val num = Math.random().toInt()

    fun printSingeLet(){
        val a = (Math.random()*10).toInt()
        println("这是一个单例类$num----$a")
    }

    fun add(num1:Int,num2:Int):Int{
        return num1+num2
    }

    fun  getRandomList(): String{
        val list = mutableListOf(1,1,1,1,1,1,1,1,1,1)
        var i = 0
        while (i<1000){
            val random = (Math.random()*10).toInt()
            list[random]++
            i++
        }
        return list.toString()
    }

    fun getHashMap(): Map<Int, String> {
        val person = Person(true)
        val person1 = Person(false)
        val hashMap = mapOf(1 to person.gender.toString(),2 to person1.gender.toString())
        return hashMap
    }
}